package cn.com.infosec.ra.util;


import javax.servlet.ServletContext;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class SpringHelper implements InitializingBean, ApplicationContextAware{

	private static 	ServletContext servletContext;
	
	
	@Override
	public void setApplicationContext(ApplicationContext arg0)
			throws BeansException {
		
	}
	
	public static Object getBean(String beanName, ServletContext servletContext){
		if(null!=servletContext){
			SpringHelper.servletContext=servletContext;
		}else{
			servletContext=SpringHelper.servletContext;
		}
		WebApplicationContext cont=  WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); 
		 return cont.getBean(beanName);
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		
	}



}
